package com.ruoyi.web.wx.controller;

import com.ruoyi.order.mapper.OrderMapper;
import com.ruoyi.user.domain.User;
import com.ruoyi.user.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Component
public class OrderTask {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private UserMapper userMapper;

    @Scheduled(cron = "0 0 0 * * ?")
    public void delOrder() {
        log.info("开始删除未支付的订单===================");
        orderMapper.deleteOrderByStatus();
    }

    // 每天 0 点执行
    @Scheduled(cron = "0 0 0 * * ?")
    public void updateQualificationsInt() {
        log.info("开始更新用户资质提交次数===================");
        List<User> users = userMapper.selectUserByCreateTime();
        log.info("用户数量：{}", users.size());
        if (!users.isEmpty()) {
            for (User user : users) {
                user.setQualificationsInt(0);
                userMapper.updateUser(user);
            }
        }
    }

}
